package com.navinfo.parkingnavi.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.navinfo.parkingnavi.R;

/*
 *com.navinfo.parkingnavi.dialog
 *zhjch
 *2020/6/1
 *19:46
 *说明（）
 */
public class RecommendDialog extends Dialog implements View.OnClickListener {

    private TextView t9, t8, t7, t6, t5, t4;
    private TextView select;
    private OnRecommendDialogListener listener;


    public void setOnDialogListener(OnRecommendDialogListener listener) {
        this.listener = listener;
    }

    public interface OnRecommendDialogListener {
        void onSelect(String name, int code);
    }

    public RecommendDialog(Context context) {
        super(context);
        setOwnerActivity((Activity) context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_recommend);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(true);
        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        getWindow().setBackgroundDrawable(new ColorDrawable(getContext().getColor(R.color.tr_bg_gray)));
        //一定要在setContentView之后调用，否则无效
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        t9 = findViewById(R.id.t9);
        t9.setOnClickListener(this);

        t8 = findViewById(R.id.t8);
        t8.setOnClickListener(this);

        t7 = findViewById(R.id.t7);
        t7.setOnClickListener(this);

        t6 = findViewById(R.id.t6);
        t6.setOnClickListener(this);
        t6.setSelected(true);
        select = t6;

        t5 = findViewById(R.id.t5);
        t5.setOnClickListener(this);

        t4 = findViewById(R.id.t4);
        t4.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        if (v != select) {
            select.setSelected(false);
            v.setSelected(true);
            select = (TextView) v;
            if (listener != null) {
                listener.onSelect(((TextView) v).getText().toString(), Integer.parseInt(String.valueOf(v.getTag())));
            }
            dismiss();
        }
    }

}
